package com.yanqu.road.server.cmd.cross.tradewar;

import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractServerCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manger.activity.TradeWarActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_TRADE_WAR_TO_SERVER_QUERY_CAN_WANTED, desc = "跨服商战通缉到被通缉的服务器查询能否通缉")
public class CrossTradeWarToServerQueryCanWantedCmd extends AbstractServerCommand {

	private int activityId;
	private long wantedUserId;
	private long queryUserId;
	private long queryServerId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarToServerQueryWantedReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarToServerQueryWantedReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		queryUserId = reqMsg.getQueryUserId();
		queryServerId = reqMsg.getQueryServerId();
		wantedUserId = reqMsg.getWantedUserId();
		return true;
	}

	@Override
	public void execute(YanQuMessage packet) throws Exception {
		ret = TradeWarActivityMgr.queryUserCanWanted(activityId,queryUserId, wantedUserId);
	}

	@Override
	public void sendData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarToServerQueryWantedRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarToServerQueryWantedRespMsg.newBuilder();
		respMsg.setActivityId(activityId);
		respMsg.setRet(ret);
		respMsg.setQueryUserId(queryUserId);
		respMsg.setQueryServerId(queryServerId);
		if(0 == ret){
			respMsg.setCanWanted(true);
		}
		int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, queryUserId);
		GamePlayerMgr.sendUnionActivityGroupPacket(CrossProtocol.C_CROSS_TRADE_WAR_TO_SERVER_QUERY_CAN_WANTED_RESP, respMsg, 0, activityId, groupId);
	}
}
